package org.dromara.system.api.feign.fallback;

import cn.hutool.http.HttpStatus;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.system.api.feign.SystemClientClient;
import org.dromara.system.api.domain.vo.RemoteClientVo;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author: zhou shuai
 * @date: 2024/9/26 20:23
 * @version: v1
 */
@Slf4j
@Component
public class SystemClientFallBack implements FallbackFactory<SystemClientClient> {

    @Override
    public SystemClientClient create(Throwable throwable) {
        log.error("SystemClientFallBack, cause:{}", throwable.getMessage());
        return new SystemClientClient() {

            @Override
            public R<RemoteClientVo> queryByClientId(String clientId) {
                return R.fail(HttpStatus.HTTP_BAD_METHOD, throwable.getLocalizedMessage());
            }
        };
    }

}
